package com.hxq.library.controller;

import com.hxq.library.service.IUserService;
import com.hxq.library.service.Impl.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @Author: Ljx
 * @Date: 2021/11/25 16:42
 * @role:
 */
@WebServlet("/selectVip")
public class SelectVipServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        HttpSession session = req.getSession();
        String account = (String) session.getAttribute("account");
        IUserService service = new UserService();
        try {
            int vip = service.selectVip(account);
            if (vip==0){
                session.setAttribute("vip1",vip);
            }else if (vip==1){
                session.setAttribute("vip1",vip);
            }else {
                session.setAttribute("vip1",vip);
            }
            resp.sendRedirect(req.getContextPath()+"selectVip.jsp");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
